<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>车辆管理</title>
<script type="text/javascript" src="../../static/scripts/json2.js"></script>
<link href="../../static/easyui/css/easyui.css" type="text/css" rel="stylesheet" />
<link href="../../static/scripts/style.css" type="text/css" rel="stylesheet" />
<link href="../../static/easyui/css/icon.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../../static/easyui/js/jquery.min.js"></script>
<script type="text/javascript" src="../../static/easyui/js/jquery.form.js"></script>
<script type="text/javascript" src="../../static/scripts/jquery.easyui.min.js"></script>
<script src="../../static/scripts/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="../../static/scripts/common.js"></script>
<script type="text/javascript" src="../../static/scripts/messageTips.js"></script>





<script>
	$(document).ready(function() {
        
	    
		// 按Enter键进行查询
    	clickEnterSearch($("#buttomSearch"));
 

		//查询按钮点击事件
		$("#buttomSearch").click(function() {
			$('#produceLabelTable').datagrid({url : '/bdCheliang/findPage',queryParams : convertArray($("#searchForm").serializeArray())});
			setTablePage($('#produceLabelTable'));
		});

		//datagrid选中行转参数
		function toChangeStorListParamStr(rows) {
			var paramStr = '';
			for ( var i = 0; i < rows.length; i++) {
				if (i == 0) {
					paramStr += 'orderIds=' + rows[i].id;
				} else {
					paramStr += "&orderIds=" + rows[i].id;
				}
			}
			return paramStr;
		}



		//datagrid选中行转参数
		function getIds(rows) {
			var paramStr = '';
			for ( var i = 0; i < rows.length; i++) {
				if (i == 0) {
					paramStr += 'ids=' + rows[i].id;
				} else {
					paramStr += "&ids=" + rows[i].id;
				}
			}
			return paramStr;
		}
		
		
        
		
		var toolbar = [{
			id : "createButton",
			text : '录入',
			iconCls : 'icon-add',
			handler : function() {
				$("#addwindom").html("");
				$("#addwindom").window({
					title : "录入",
					href : '/webpage/easypoi/cheliangAdd.html',
					width : 400,
					height :450,
					modal : true
				});
			}
		},{
			id : "editButton",
			text : '编辑',
			iconCls : 'icon-edit',
			handler : function() {
				var rows = $("#produceLabelTable").datagrid('getSelections');
				if (rows.length == 0) {
					$.messager.alert('提示', '请选择一条记录修改', 'info');
				}else if (rows.length > 1) {
					$.messager.alert('提示', '一次只能选择一条记录', 'info');
				}else{
					$("#addwindom").html("");
					$("#addwindom").window({
						title : "修改",
						href :  '/webpage/easypoi/cheliangUpdate.html',
						width : 350,
						height : 500,
						modal : true
					});
				}

			}
		},{
			id : "deleteButton",
			text : '批量删除',
			iconCls : 'icon-remove',
			handler : function() {
				var rows = $("#produceLabelTable").datagrid('getSelections');
				var param = getIds(rows);
				$.messager.confirm('提示', '是否删除选中的记录？', function(r) {
					if (r) {
						$.ajax({
							type : "POST",
							url : '/bdCheliang/deleteCheliang',
							data : param,
							success : function(response) {
								if (response == "success")
								{
									$.messager.alert('提示', '删除成功', 'info', function() {
										$('#produceLabelTable').datagrid('reload');
										$('#produceLabelTable').datagrid('clearSelections');
									});
								}
								else
								{
									$.messager.alert('提示', '删除失败，'+ response, 'error', function() {});
								}
							},
							error : function()
							{
								$.messager.alert('提示', '删除失败', 'error', function() {});
							}
						});
					}
				});
			}
		},{
			id : "createButton",
			text : '导入',
			iconCls : 'icon-put',
			handler : function(){
				$("#addwindom").window({
					title : "导入数据",
					href : '/webpage/easyexcel/cheliangImport.html',
					width : 450,
					height : 180,
					modal : true
				});
			}
		},{
			id : "exportButton",
			text : '导出',
			iconCls : 'icon-putout',
			handler : function() {

				var param = convertArray($("#searchForm").serializeArray());
				$.ajax({
					type : "POST",
					dataType:"json",
					url : '/bdCheliang/exportExcel',
					data: param,
					success : function(response) {
						if (response.success) {
							$('#searchForm').mask("hide");
							window.location.href = "/excel/"+response.url;
						} else {
							$.messager.alert('提示', '数据导出失败', 'error', function() {});
							$('#searchForm').mask("hide");
						}
					}
				});



			}
		},{
			id : "createButton",
			text : '模板下载',
			iconCls : 'icon-putout',
			handler : function() {
				// input搜索框参数
				var param = convertArray($("#searchForm").serializeArray());

				var form = $("<form>");
				form.attr('style', 'display:none');
				form.attr('target', '');
				form.attr('method', 'post');
				form.attr('action', '/bdCheliang/modelExcel');


				$('body').append(form);

				form.submit();
				form.remove();
			}
		}];
		
		

		$('#produceLabelTable').datagrid({
			title : '车辆管理',
			width : 'auto',
			height : 'auto',
			remoteSort : true,
			sortable : true,
			fit : true,
			nowrap : false,
			border:false,
			striped : true,
			loadMsg : '数据装载中......',
			sortOrder : 'asc,desc',
			remoteSort : true,
			toolbar : toolbar,
			idField:'', 
			frozenColumns : [ [ {
				field : 'ids',
				checkbox : true
			} ] ],
			toolbar : toolbar,
			columns : [ [{
				title : 'ID',
				sortable : true,
				field : 'id',
				width : '95',
				rowspan : 1,
				align : 'center',
				hidden:'true'
			},{
				title : '车牌号',
				sortable : true,
				field : 'chepaihao',
				width : '95',
				rowspan : 1,
				align : 'center'
			},{
				title : '车型',
				sortable : true,
				field : 'chexing',
				width : '95',
				rowspan : 1,
				align : 'center'
			},{
				title : '最大体积',
				sortable : true,
				field : 'zaizhong',
				width : '95',
				rowspan : 1,
				align : 'center'
			},{
				title : '载重',
				sortable : true,
				field : 'produceDate',
				width : '95',
				rowspan : 1,
				align : 'center'
			},{
				title : '载人数',
				sortable : true,
				field : 'zairen',
				width : '95',
				rowspan : 1,
				align : 'center'
			},{
				title : '准驾驾照',
				sortable : true,
				field : 'jiazhao',
				width : '95',
				rowspan : 1,
				align : 'center'
			},{
				title : '是否可用',
				sortable : true,
				field : 'zhuangtai',
				width : '95',
				rowspan : 1,
				align : 'center'
			},{
				title : '备注',
				sortable : true,
				field : 'beizhu',
				width : '95',
				rowspan : 1,
				align : 'center'
			},{
				title : '默认司机',
				sortable : true,
				field : 'username',
				width : '95',
				rowspan : 1,
				align : 'center'
			},{
				title : 'GPS',
				sortable : true,
				field : 'gpsid',
				width : '95',
				rowspan : 1,
				align : 'center'
			},{
				title: '操作',
				field: 'operate',
				align: 'center',
				formatter:function(value, row, index){

					var str = '<button onclick="delOne(this)">删除</button> ';
					return str;
				}}] ],
			pagination : true,
			rownumbers : true,
			onLoadSuccess:function(data){

			},
		});
		/* if(paramStr==null ||paramStr == ''){
			setButtonNew(toolbar,"9111");
		} */
		setTablePage($('#produceLabelTable'));	
	});

	function getRowIndex(target) {
		var tr = $(target).closest('tr.datagrid-row');
		return parseInt(tr.attr('datagrid-row-index'));
	}

	/**
	 * 删除
	 * @param id
	 */
	function delOne(target) {
		var rows = $('#produceLabelTable').datagrid('getRows');

			var delId =(rows[getRowIndex(target)]['id']); //获取指定列

		$.ajax({
			url: "/bdCheliang/deleteOneCheliang",
			type: "POST",
			data : {
				"id": delId
			},
			success : function(data) {
				if (data) {//请求成功
					alert(data);
					$('#produceLabelTable').datagrid('reload');
					$('#produceLabelTable').datagrid('clearSelections');
				} else {
					alert(data);
				}

			},
			error: function (data) {
				alert("删除失败");
				$('#produceLabelTable').datagrid('reload');
				$('#produceLabelTable').datagrid('clearSelections');
			}
		})
	}
	
	
	

	function GetQueryString(name)
	{
	     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	     var r = window.location.search.substr(1).match(reg);
	     if(r!=null){
	    	 return  unescape(r[2]); 
	     }
	     return null;
	}

	function resetBtn(){

		document.getElementById('searchForm').reset();

	}
</script>


</head>
<body>
   
	<div class="easyui-layout" data-options="fit:true">
	    
	      <!--   查询条件部分 -->
	      <div data-options="region:'north',title:'',bodyCls:'Mnolrtborder'" style="height: 100px;">
                             
			<form id="searchForm">
				<table style="margin: 0 auto; margin-top: 20px;">
				    <tr>
				     
						<td class="m-info-title">车牌号：</td>
						<td class="m-info-input">
							<input type="text" id="searchKey" class="Msearch-key"  style="width: 130px; height: 27px;" name="searchKey" />
						</td>


						<td class="m-info-title">车型：</td>
						<td class="m-info-input">
							<input type="text" id="searchKey2" class="Msearch-key"  style="width: 130px; height: 27px;" name="searchKey2" />

						</td>

						
						<td class="m-info-title">准驾驾照：</td>
						<td class="m-info-input">
							<input type="text" id="searchKey3" class="Msearch-key"  style="width: 130px; height: 27px;" name="searchKey3" />

						</td>
						<td>

							<span style="float:right;padding-left: 30px">
								<a id="buttomSearch" href="#" class="easyui-linkbutton" iconCls="icon-search" >查询</a>
							</span>
						</td>
						<td></td>

						<td>
							<span style="float:right">
								<a id="buttomSearch2" onclick="resetBtn()" href="#" class="easyui-linkbutton" iconCls="icon-reload" >重置</a>
							</span>
						</td>
					</tr>
				</table>
			</form>
		</div>
		
		<!-- 列表部分 -->
		<div data-options="region:'center',title:'',bodyCls:'Mnolrbborder'">
			<table id="produceLabelTable">
			</table>
		</div>
		
		<!-- 弹出窗口部分 -->
	    <div id="addwindom" style="margin: 0 auto;"></div>
	</div>

</body>
</html>